<h1>SoundStreamHead2</h1>

<p>SoundStreamHead2 defines the format of a streaming sound, identifying the 
encoding scheme, the rate at which the sound will be played and the size of the 
decoded samples. The actual sound is streamed used a SoundStreamBlock which 
contains the data for each frame in a movie.</p>

<table>

<tr>
<th nowrap>Field Name</th>
<th>Type</th>
<th>Size</th>
<th>Description</th>
</tr>

<tr>
<td nowrap valign="top">type</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">10</td>
<td>Identifies the SoundStreamHead instruction when it is encoded. It is encoded 
with the length field as a 16-bit integer (Little-endian byte order).</td>
</tr>

<tr>
<td nowrap valign="top">length</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">6</td>
<td>The length in bytes of the body of the instruction when it is encoded. If the length is greater 
than 62 then this field is set to 0x3F and the length is encoded using the 
extendedLength field. Encoded with the type field as a 16-bit integer.</td>
</tr>

<tr>
<td nowrap valign="top">extendedLength</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">32</td>
<td>Optional. Contains the length in bytes of the encoded instruction if it is
greater than 62 bytes. If the length is 62 bytes or less then this field is 
omitted.</td>
</tr>

<tr>
<td nowrap valign="top">format</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">4</td>
<td>A code identifying the format of the encoded sound data: 0 = NATIVE_PCM, 
1 = ADPCM, 2 = MP3, 3 = PCM, 6 = NELLYMOSER.</td>
</tr>

<tr>
<td nowrap valign="top">playbackRate</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">2</td>
<td>A code identifying the rate the sound will be played in Hertz: 0 = 5.5KHz, 
1 = 11Khz, 2 = 22KHz or 3 = 44.1KHz.</td>
</tr>

<tr>
<td nowrap valign="top">playbackSampleSize</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">1</td>
<td>A code identifying the number of bits in a sample: 0 = 8-bit, 1 = 16-bit.</td>
</tr>

<tr>
<td nowrap valign="top">playbackChannels</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">1</td>
<td>A code identifying the number of channels in the sound: 0 = mono or 1 = stereo.</td>
</tr>

<tr>
<td nowrap valign="top">streamRate</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">2</td>
<td>A code identifying the rate the streaming sound will be played in Hertz: 0 = 5.5KHz, 
1 = 11Khz, 2 = 22KHz or 3 = 44.1KHz.</td>
</tr>

<tr>
<td nowrap valign="top">streamSampleSize</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">1</td>
<td>A code identifying the number of bits in a streaming sound sample: 0 = 8-bit, 1 = 16-bit.</td>
</tr>

<tr>
<td nowrap valign="top">streamChannels</td>
<td nowrap valign="top">unsigned bit</td>
<td nowrap valign="top" align="right">1</td>
<td>A code identifying the number of channels in the streaming sound: 0 = mono or 1 = stereo.</td>
</tr>

<tr>
<td nowrap valign="top">streamSampleCount</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">32</td>
<td>The number of samples in the streaming sound defined in the SoundStreamBlock.</td>
</tr>

<tr>
<td nowrap valign="top">latency</td>
<td nowrap valign="top">unsigned int</td>
<td nowrap valign="top" align="right">16</td>
<td>Latency defines the number of samples to skip only when playing sounds encoded 
with the MP3 format.</td>
</tr>

</table>

<p>Three encoded formats for the sound data are supported:</p>

<div style="padding-left:20px; margin-bottom:10px;">
<ul>

<li>NATIVE_PCM - uncompressed Pulse Code Modulated: samples are either 1 or 2 bytes. 
For two-byte samples the byte order is dependent on the platform on which the Flash
Player is hosted. Sounds created on a platform which supports big-endian byte order 
will not be played correctly when listened to on a platform which supports 
little-endian byte order.</li>

<li>PCM - uncompressed Pulse Code Modulated: samples are either 1 or 2 bytes with 
the latter presented in Little-Endian byte order. This ensures that sounds can be 
played across different platforms.</li>

<li>ADPCM - compressed ADaptive Pulse Code Modulated: samples are encoded and compressed
by comparing the difference between successive sound sample which dramatically reduces
the size of the encoded sound when compared to the uncompressed PCM formats. Use this 
format whenever possible.</li>

<li>MP3 - compressed MPEG Audio Layer-3.</li>

<li>NELLYMOSER - compressed Nellymoser Asao format supporting low bit-rate sound 
for improving synchronisation between the sound and frame rate of movies.</li>

</ul>
</div>

<p>When a stream sound is played if the Flash Player cannot render the frames fast enough 
to maintain synchronisation with the sound being played then frames will be skipped. 
Normally the player will reduce the frame rate so every frame of a movie is played. 
The different sets of attributes that identify how the sound will be played compared 
to the way it was encoded allows the Player more control over how the animation is 
rendered. Reducing the resolution or playback rate can improve synchronization with 
the frames displayed.</p>

<h2>History</h2>

<p>The SoundStreamHead2 instruction represents the SoundStreamHead structure from the 
Flash specification. It was introduced in Flash 3. Support for the Nellymoser Asao
format was added in Flash 6.</p>
